package com.example.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/redis")
@RestController
public class RedisController {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping("/set")
    public String setK(String key, String v) {
        stringRedisTemplate.opsForValue().set(key, v);
        return "ok";
    }

    @GetMapping("/get/{key}")
    public String getK(@PathVariable("key") String key) {
        return stringRedisTemplate.opsForValue().get(key);
    }
}
